﻿@model BcdFileListViewModel
@{
    Layout = null;
    ViewBag.Title = "案卷目录首页";
    string type = ViewBag.Type;
}
<style type="text/css">
    .ztree .span1 {
        color: #0a9c1d;
    }

    .ztree .span2 {
        color: #ff6a00;
    }

    .ztree .span3 {
        color: #0026ff;
    }
</style>
<script type="text/javascript">
    var jgzl_ajml_zTree_@(type);
    var jgzl_ajml_zTree_setting = {
        treeId: "jgzl_ajml_zTree_@(type)",
        isSimpleData: true,              //数据是否采用简单 Array 格式，默认false
        treeNodeKey: "id",               //在isSimpleData格式下，当前节点id属性
        treeNodeParentKey: "pId",        //在isSimpleData格式下，当前节点的父节点id属性
        showLine: true,                  //是否显示节点间的连线
        checkable: false,                  //每个节点上是否显示 CheckBox
        async: true,
        asyncUrl: "/CompletionMaterials/FileList/AsyncFileDataJson",  //获取节点数据的URL地址
        asyncParam: ["proId", "id"],
        asyncParamOther: { "type": "@(type)" },
        callback: {
            click: jgzl_ajml_zTree_click
        }
    };
    $(function () {
        $.getJSON(
           "/CompletionMaterials/FileList/AsyncFileDataJson?type=@(type)",
            function (data) {
                jgzl_ajml_zTree_@(type) = $("#jgzl_ajml_zTree_@(type)").zTree(jgzl_ajml_zTree_setting, data);
                if (data.length > 0) {
                    $("#jgzl_ajml_list_@(type)").loadUrl(
                        '/CompletionMaterials/FileList/Detail',
                        "tab_i=0&type=@(type)&proId=" + data[0].proId + "&id=" + data[0].id,
                        function (message) {
                            $('#jgzl_ajml_list_@(type)').parent().find("[layoutH]").layoutH();

                        });
                    }
            });
    })
    //点击事件
    function jgzl_ajml_zTree_click(event, treeId, treeNode) {
        $("#Li_FileList_Select@(type)").attr("style", "");
        if (treeNode.pId == null)
            $("#Li_FileList_Edit@(type)").attr("style", "");
        else
            $("#Li_FileList_Edit@(type)").attr("style", "display:none;");
        $("#Li_FileList_Delete@(type)").attr("style", "");
        $("#CompletionMaterials_FileList_Select@(type)").attr("href", "/CompletionMaterials/FileList/Select?proId=" + treeNode.proId + "&id=" + treeNode.id);
        $("#CompletionMaterials_FileList_Edit@(type)").attr("href", "/CompletionMaterials/FileList/Edit?proId=" + treeNode.proId);
        var tab_i = 0;
        if ($("#ul_filelist@(type)").length > 0) {
            var i = 0;
            $("#ul_filelist@(type) li").each(function () {
                if ($(this).attr("class") == "selected") {
                    tab_i = i;
                }
                i++;
            });
        }
        $("#jgzl_ajml_list_@(type)").loadUrl('/CompletionMaterials/FileList/Detail', "tab_i=" + tab_i + "&type=@(type)&proId=" + treeNode.proId + "&id=" + treeNode.id, function (message) {
            $('#jgzl_ajml_list_@(type)').parent().find("[layoutH]").layoutH();
        });
    }

    //删除
    function DeleteType() {
        debugger;
        var node = jgzl_ajml_zTree_@(type).getSelectedNode();
        if (node != null) {
            alertMsg.confirm("将同时删除与其关联的案卷信息，您确定要删除吗？", {
                okCall: function () {
                    $.post("/CompletionMaterials/FileList/Delete", { proId: node.proId, id: node.id }, refre_jgzl_ajml_index, "json");
                }
            });
        } else {
            alertMsg.error("请选一条信息！");
        }
    }
    //刷新ztree
    function refre_jgzl_ajml_index(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            if (json.type == "add") {
                var pNode = null;
                if (json.pId != null)
                    pNode = jgzl_ajml_zTree_@(type).getNodeByParam("id", json.pId);
                jgzl_ajml_zTree_@(type).addNodes(pNode, { proId: json.proId, pId: json.pId, id: json.id, name: json.name, target: "ajax", url: "/CompletionMaterials/FileList/Detail?type=@(type)&proId=" + json.proId + "&id=" + json.id }); //页面上添加节点
                var node = jgzl_ajml_zTree_@(type).getNodeByParam("id", json.id);
                $("#" + node.tId).initUI();
                jgzl_ajml_zTree_@(type).selectNode(node);
                $("#CompletionMaterials_FileList_Select@(type)").attr("href", "/CompletionMaterials/FileList/Select?proId=" + json.proId + "&id=" + json.id);
                $("#CompletionMaterials_FileList_Edit@(type)").attr("href", "/CompletionMaterials/FileList/Edit?proId=" + json.proId);
                var tab_i = 0;
                if ($("#ul_filelist@(type)").length > 0) {
                    var i = 0;
                    $("#ul_filelist@(type) li").each(function () {
                        if ($(this).attr("class") == "selected") {
                            tab_i = i;
                        }
                        i++;
                    });
                }
                $("#jgzl_ajml_list_@(type)").loadUrl('/CompletionMaterials/FileList/Detail', "tab_i=" + tab_i + "&type=@(type)&proId=" + json.proId + "&id=" + json.id, null);
                $.pdialog.closeCurrent();
            }
            if (json.type == "edit") {
                var node = jgzl_ajml_zTree_@(type).getNodeByParam("id", json.id);
                node.name = json.name;
                jgzl_ajml_zTree_@(type).updateNode(node);
                jgzl_ajml_zTree_@(type).selectNode(node);
                $("#CompletionMaterials_FileList_Select@(type)").attr("href", "/CompletionMaterials/FileList/Select?proId=" + json.proId + "&id=" + json.id);
                $("#CompletionMaterials_FileList_Edit@(type)").attr("href", "/CompletionMaterials/FileList/Edit?proId=" + json.proId);
                var tab_i = 0;
                if ($("#ul_filelist@(type)").length > 0) {
                    var i = 0;
                    $("#ul_filelist@(type) li").each(function () {
                        if ($(this).attr("class") == "selected") {
                            tab_i = i;
                        }
                        i++;
                    });
                }
                $("#jgzl_ajml_list_@(type)").loadUrl('/CompletionMaterials/FileList/Detail', "tab_i=" + tab_i + "&type=@(type)&proId=" + json.proId + "&id=" + json.id, null);
                $.pdialog.closeCurrent();
            }
            if (json.type == "delete") {
                var node = jgzl_ajml_zTree_@(type).getNodeByParam("id", json.id);
                jgzl_ajml_zTree_@(type).removeNode(node);
                $("#CompletionMaterials_FileList_Select@(type)").attr("href", "/CompletionMaterials/FileList/Select?proId=null&id=null");
                $("#CompletionMaterials_FileList_Edit@(type)").attr("href", "/CompletionMaterials/FileList/Edit?proId=null");
                $("#jgzl_ajml_list_@(type)").html("");
                $("#Li_FileList_Edit@(type)").attr("style", "display:none;");
                $("#Li_FileList_Select@(type)").attr("style", "display:none;");
                $("#Li_FileList_Delete@(type)").attr("style", "display:none;");
            }
            if (json.type == "sel") {
                //刷新节点
                var node = jgzl_ajml_zTree_@(type).getNodeByParam("id", json.id);
                node.isParent = json.isParent;
                jgzl_ajml_zTree_@(type).updateNode(node);
                jgzl_ajml_zTree_@(type).reAsyncChildNodes(node, "refresh", true)
                jgzl_ajml_zTree_@(type).expandNode(node, true, true, true);
                //$("#" + node.tId + "_ul").initUI();
            }
            //审核刷新树
            if (json.type == "check") {
                //刷新节点
                var node = jgzl_ajml_zTree_@(type).getNodeByParam("id", json.id);
                node.name = json.name;
                jgzl_ajml_zTree_@(type).updateNode(node);
            }
        }
    }
</script>


<div class="page" style="border-top: 1px solid #b8d0d6;" layouth="1">
    <div class="leftPanel" style="width: 300px;">
        <div class="panelBar" style="width: 298px;">
            <ul class="toolBar">
                <li>@Html.PermissionButton("CompletionMaterials.FileList.Create" + type, "CompletionMaterials_FileList_Create" + type, "add", "/CompletionMaterials/FileList/Create?type=" + type, "new", "dialog", "添加工程", "true", "480", "350", "添加")</li>
                <li id="Li_FileList_Select@(type)" style="display:none;">@Html.PermissionButton("CompletionMaterials.FileList.Select" + type, "CompletionMaterials_FileList_Select" + type, "add", "/CompletionMaterials/FileList/Select?proId=null&id=null", "new", "dialog", "选择资料类型", "true", "480", "480", "资料类型")</li>
                <li id="Li_FileList_Edit@(type)" style="display:none;">@Html.PermissionButton("CompletionMaterials.FileList.Edit" + type, "CompletionMaterials_FileList_Edit" + type, "edit", "/CompletionMaterials/FileList/Edit?proId=null&id=null", "new_edit", "dialog", "修改", "true", "400", "290", "修改")</li>
                <li id="Li_FileList_Delete@(type)" style="display:none;">@Html.PermissionButton("CompletionMaterials.FileList.Delete" + type, "CompletionMaterials_FileList_Delete" + type, "delete", "javascript:DeleteType();", "", "", "", "", "删除")</li>
            </ul>
        </div>
        <div class="pageContent" layouth="28">
            <ul id="jgzl_ajml_zTree_@(type)" class="ztree"></ul>
        </div>
    </div>
    <div id="jgzl_ajml_list_@(type)" class="rightPanel">
    </div>
</div>
